package seed_secondhand

import (
	"fmt"
	"gitee.com/theegg/go-brick/app/model/secondhand/sh_goods"
	"gitee.com/theegg/go-brick/app/model/user/users"
	"github.com/xormplus/xorm"
)

// 二手物品 ==
func InitSeedSecondhandGoods(db *xorm.Engine) {

	items := make(map[int]*sh_goods.AddParams)

	items[1] = &sh_goods.AddParams{
		SellerId:    1,
		GoodsTitle:  "出售一部二手IPHONE X",
		TypeId:      1,
		GoodsDesc:   "iPhone X 64gb .. 2万出售 .. 右上角屏幕一点黑 但不影响触碰 .. 会提供全新充电器",
		DistrictId:  100,
		CatId:       3,
		BoughtPrice: 2500,
		SalePrice:   1800,
		ImageCover:  "",
		ImageList:   "",
		BoughtTime:  "2018-09-21 00:00:00",
	}

	items[2] = &sh_goods.AddParams{
		SellerId:    1,
		GoodsTitle:  "求购印度神油",
		TypeId:      2,
		GoodsDesc:   "印度神油",
		DistrictId:  100,
		CatId:       3,
		BoughtPrice: 2500,
		SalePrice:   1800,
		ImageCover:  "",
		ImageList:   "",
		BoughtTime:  "2018-09-21 00:00:00",
	}

	count := 0
	errCount := 0
	for _, item := range items {
		model := new(sh_goods.SecondhandGoods)
		user, errUser := users.GetItemById(item.SellerId)
		if errUser != nil {
			fmt.Println(errUser.Error())
			errCount++
			continue
		}

		err := model.AddOrUpdate(*item, user)
		if err != nil {
			fmt.Println(err.Error())
			errCount++
			continue
		}

		count++
	}

	fmt.Printf("%5s|%25s|%10d|%8d|\n", "", "secondhand_goods", count, errCount)
}
